from data_pre import data_pre, write_csv
import sys
import re
sys.path.append("../")
from dataStorage.data_import import data_import 
from file_filtering import file_filtering

table_name = ['Hadoop', 'Java', 'python', 'AI', 'DA', 'DV', "DM", "DAn", "IM", "ML", "DL", "CV", "MV"]

csv_file = file_filtering("..\\reptile",suffix={"content":".csv","status":0}, prefix={"content":"url","status":1})

for i,file in enumerate(csv_file):
    csv_name = re.compile(r'\w+')
    print(csv_name.findall(file)[-2])
    data = data_pre(file)
    write_csv(f"./{csv_name.findall(file)[-2]}_handle.csv", data)

    db = data_import()
    db.write_to_db(f"./{csv_name.findall(file)[-2]}_handle.csv", table_name[i], csv_name.findall(file)[-2]) 
db.close()